package com.dc.wifi.main.adapter;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.dc.wifi.main.ui.fragment.HomeFragment;
import com.dc.wifi.main.ui.fragment.MallFragment;
import com.dc.wifi.main.ui.fragment.MineFragment;

import java.util.ArrayList;
import java.util.List;
import java.util.zip.Inflater;

public class MyFragmentPagerAdapter extends FragmentPagerAdapter {

    private String[] mTitles = new String[]{"首页", "商城", "我的"};
    private List<Fragment> list;
    private HomeFragment homeFragment;
    private MallFragment mallFragment;
    private MineFragment mineFragment;

    public MyFragmentPagerAdapter(@NonNull FragmentManager fm, int behavior) {
        super(fm, behavior);
        homeFragment =HomeFragment.Companion.createFragment(new Bundle());
        mallFragment =MallFragment.Companion.createFragment(new Bundle());
        mineFragment =MineFragment.Companion.createFragment(new Bundle());


    }


    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
            return homeFragment;
        } else if (position == 1) {
            return mallFragment;
        } else if (position == 2) {
            return mineFragment;
        }
        return homeFragment;
    }

    @Override
    public int getCount() {
        return mTitles.length;
    }

    //ViewPager与TabLayout绑定后，这里获取到PageTitle就是Tab的Text
    @Override
    public CharSequence getPageTitle(int position) {
        return mTitles[position];
    }
}